package com.foreveross.vo;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.springframework.format.annotation.DateTimeFormat;

import com.foreveross.common.Constants;

/**
 * 物业报修 HouseRepair entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "house_repair", catalog = "hrtenement")
public class HouseRepair implements java.io.Serializable {

	// Fields

	private String id;
	private HouseUser houseUser;
	private String repairNo;
	private String address;
	private String url;
	private String content;
	private String phone;
	private Integer status;
	private HrCode type;
	private HrHouses hrHouses;
	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	private Date createTime;

	private String[] urlArray;

	private Integer isCertification;
	private String cityId;
	private String home;
	private String houseUnit;

	private String codeDesc;
	
	private String hrHousesName;
	
	private String houseUserName;
	
	private Date handlingTime;
	
	private String  typeName;

	// Constructors

	/** default constructor */
	public HouseRepair() {
	}

	/** minimal constructor */
	public HouseRepair(String id) {
		this.id = id;
	}

	public HouseRepair(String id, String repairNo, String address,
			HrCode type, Integer status, String url, String codeDesc) {
		this.id = id;
		this.repairNo = repairNo;
		this.address = address;
		this.url = url;
		this.type = type;
		this.status = status;
		this.codeDesc = codeDesc;
	}

	/** full constructor */
	public HouseRepair(String id, HouseUser houseUser, String repairNo, String address, String url, String content,
			String phone, Integer status, HrCode type, HrHouses hrHouses,
			Date createTime) {
		this.id = id;
		this.houseUser = houseUser;
		this.repairNo = repairNo;
		this.address = address;
		this.url = url;
		this.content = content;
		this.phone = phone;
		this.status = status;
		this.type = type;
		this.hrHouses = hrHouses;
		this.createTime = createTime;
	}

	// Property accessors
	@Id
	@GenericGenerator(name = "idGenerator", strategy = "uuid")
	@GeneratedValue(generator = "idGenerator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id")
	@NotFound(action=NotFoundAction.IGNORE)
	public HouseUser getHouseUser() {
		return this.houseUser;
	}

	public void setHouseUser(HouseUser houseUser) {
		this.houseUser = houseUser;
	}

	@Column(name = "repair_no")
	public String getRepairNo() {
		return this.repairNo;
	}

	public void setRepairNo(String repairNo) {
		this.repairNo = repairNo;
	}

	@Column(name = "address")
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "url")
	public String getUrl() {
		return this.url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name = "content")
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "phone")
	public String getPhone() {
		return this.phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "status")
	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "type")
	@NotFound(action=NotFoundAction.IGNORE)
	public HrCode getType() {
		return this.type;
	}

	public void setType(HrCode type) {
		this.type = type;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "house_id")
	@NotFound(action=NotFoundAction.IGNORE)
	public HrHouses getHrHouses() {
		return hrHouses;
	}

	public void setHrHouses(HrHouses hrHouses) {
		this.hrHouses = hrHouses;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Transient
	public String[] getUrlArray() {
		if (this.url != null && !this.url.isEmpty()) {
			String imgAaary[]=this.url.split(",");
			for(int i=0;i<imgAaary.length;i++)
			{
				imgAaary[i]=Constants.WEBAPP_PATH+imgAaary[i];
			}
			return imgAaary;
		}
		return urlArray;
	}

	public void setUrlArray(String[] urlArray) {
		this.urlArray = urlArray;
	}

	public Integer getIsCertification() {
		return isCertification;
	}

	public void setIsCertification(Integer isCertification) {
		this.isCertification = isCertification;
	}

	public String getCityId() {
		return cityId;
	}

	public void setCityId(String cityId) {
		this.cityId = cityId;
	}

	public String getHome() {
		return home;
	}

	public void setHome(String home) {
		this.home = home;
	}

	@Column(name = "house_unit")
	public String getHouseUnit() {
		return houseUnit;
	}

	public void setHouseUnit(String houseUnit) {
		this.houseUnit = houseUnit;
	}

	@Transient
	public String getCodeDesc() {
		return codeDesc;
	}

	public void setCodeDesc(String codeDesc) {
		this.codeDesc = codeDesc;
	}

	@Transient
	public String getHrHousesName() {
		if(hrHouses!=null)
			return hrHouses.getName();
		return hrHousesName;
	}

	public void setHrHousesName(String hrHousesName) {
		this.hrHousesName = hrHousesName;
	}

	@Transient
	public String getHouseUserName() {
		if(houseUser!=null)
			return houseUser.getName();
		return houseUserName;
	}

	public void setHouseUserName(String houseUserName) {
		this.houseUserName = houseUserName;
	}
	
	@Column(name = "handling_time")
	public Date getHandlingTime() {
		return handlingTime;
	}

	public void setHandlingTime(Date handlingTime) {
		this.handlingTime = handlingTime;
	}
	
	@Column(name = "type_name")
	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}
	
	

}